//
//  UpgradeLayer.h
//  ATM Killer
//
//  Created by Cloner Team on 9/9/14.
//
//

#ifndef UPGRADE_LAYER
#define UPGRADE_LAYER

#include "AbstractLayer.h"
using namespace extension;
class UpgradeLayer : public AbstractLayer {
    UG_PROPERTY_FULL(__Dictionary*, avatarDict, AvatarDict);
    UG_PROPERTY_FULL(__Array*, cardArray, CardArray);
    UG_PROPERTY_FULL(__Array*, pageButtons, PageButton);
    UG_PROPERTY_FULL(MenuItemSprite*, levelUpButton, LevelUpButton);
    UG_PROPERTY_FULL(MenuItemSprite*, hireButton, HireButton);
    UG_PROPERTY_FULL(MenuItemSprite*, purchaseButton, PurchaseButton);
    UG_PROPERTY_FULL(MenuItemSprite*, continueButton, ContinueButton);
    UG_PROPERTY_FULL(MenuItemSprite*, skipButton, SkipButton);
    UG_PROPERTY_FULL(MenuItemSprite*, scrollButtonUp, ScrollButtonUp);
    UG_PROPERTY_FULL(MenuItemSprite*, scrollButtonDown, ScrollButtonDown);
    UG_PROPERTY_FULL(MenuItemSprite*, okButton, OkButton);
    UG_PROPERTY_FULL(MenuItemSprite*, cancelButton, CancelButton);
    UG_PROPERTY_FULL(Label*, characterNameLabel, CharacterNameLabel);
    UG_PROPERTY_FULL(Label*, currentMoneyLabel, CurrentMoneyLabel);
    UG_PROPERTY_FULL(Label*, levelLabel, LevelLabel);
    UG_PROPERTY_FULL(Label*, timeUpgradeLabel, TimeUpgradeLabel);
    UG_PROPERTY_FULL(Label*, timeClockLabel, ClockLabel);
    UG_PROPERTY_FULL(Label*, totalAtmBonusLabel, TotalAtmBonusLabel);
    UG_PROPERTY_FULL(Label*, levelUpCostLabel, CharacterEarnLabel);
    UG_PROPERTY_FULL(Label*, characterMpsLabel, CharacterMpsLabel);
    UG_PROPERTY_FULL(Label*, upgradeNameLabel, UpgradeNameLabel);
    UG_PROPERTY_FULL(Label*, upgradeEffectLabel, UpgradeEffectLabel);
    UG_PROPERTY_FULL(Label*, upgradeDescLabel, UpgradeDescLabel);
    UG_PROPERTY_FULL(Label*, upgradeCostLabel, UpgradeEarnLabel);
    UG_PROPERTY_FULL(Label*, requiredLevelLabel, RequiredLevelLabel);
    UG_PROPERTY_FULL(ProgressTimer*, timeBar, TimeBar);
    UG_PROPERTY_FULL(Face*, downBar, DownBar);
protected:
    int avatarChoice = -1;
    int cardChoice = -1;
    int cardDirection = NUM_CARDS_HALT;
    bool swipe = false;
    bool availablePopUp;
    int contentOffsetSpeed;
    float finishContentOffset;
    cocos2d::Point pointSwipe;
    float timeOfSwipe = 0.0f;
    
    GameModel* gameModel;
    UGLayerColor* grayLayer;
    UGLayer* mainLayer;
    UGLayer* popUpLayer;
    UGLayer* avatarLayer;
    UGLayer* cardsLayer;
    ScrollView* avatarContentView;
    ScrollView* cardContentView;
    Face* characterBoard;
    Face* popUpFace;
    UpgradeListener* upgradeListener;
    NotificationListener* notiListener;
    
    int currentCharacterID;
    int currentUpgradeID;
    int currentChoosenPage;
    bool isPopUpShow;
    bool isSkipPopUpShow;
    void onTouchesBegan(const std::vector<Touch*>& touches, Event* event);
    void onTouchesMoved(const std::vector<Touch*>& touches, Event* event);
    void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);

private:
    UpgradeLayer();
    ~UpgradeLayer();
    void initialize();
    void createLayers();
    void createLayersContent();
    virtual void onEnter();
    virtual void onExit();
    
    void loadCharacterBoard();
    void loadPopUp();
    void touchesRegister();
    
    void onButtonClick(Ref* sender);
    void onChangeCharacter(Ref* data);
    void onShowNotification(Ref* data);
    void onRemoveNotification(Ref* data);
    
    void showLevelUpPopUp(Ref* sender);
    void showUpgradePopUp(Ref* sender);
    void showSkipTimePopUp(Ref* sender);
    void cancelPopUp(Ref* sender);
    void createCards();
    void arrangeCards();
    void createPageButtons();
public:
    CREATE_FUNC(UpgradeLayer);
    void update(float dt);
    
};

#endif /* defined(__ATM_Killer__UpgradeLayer__) */
